home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / unix / volume15 / inc-elim < prev    next >
Encoding:
Internet Message Format  |  1988-05-30  |  16.3 KB

  1. Subject:  v15i024:  Filter to eliminate file inclusion commands
  2. Newsgroups: comp.sources.unix
  3. Sender: sources
  4. Approved: rsalz@uunet.UU.NET
  5.  
  6. Submitted-by: Sten Folkerman <sten@enea.se>
  7. Posting-number: Volume 15, Issue 24
  8. Archive-name: inc-elim
  9.  
  10. [  This is a general filter to remove "include" commands from files.
  11.    It can process ".so" commands for *roff, "#include" commands for
  12.    C, etc.  It understands ~name and | for piped commands.
  13.  
  14.    The Makefile will cause problems for folks without the SystemV
  15.    "augmented make", so use the Make.Alt that I wrote.
  16.  
  17.    The manual page uses the "C" font; if you don't have it
  18.    you might need to do some tweaking -- check out all \f
  19.    commands.
  20.  
  21.    -r$  ]
  22.  
  23. #! /bin/sh
  24. # This is a shell archive.  Remove anything before this line, then unpack
  25. # it by saving it into a file and typing "sh file".  To overwrite existing
  26. # files, type "sh file -c".  You can also feed this as standard input via
  27. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  28. # will see the following message at the end:
  29. #        "End of shell archive."
  30. # Contents:  Make.alt Makefile file1 file2 inc-elim inelim.1net
  31. #   inelim.c unenv.c
  32. # Wrapped by rsalz@fig.bbn.com on Tue May 31 16:14:00 1988
  33. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  34. if test -f 'Make.alt' -a "${1}" != "-c" ; then 
  35.   echo shar: Will not clobber existing file \"'Make.alt'\"
  36. else
  37. echo shar: Extracting \"'Make.alt'\" \(737 characters\)
  38. sed "s/^X//" >'Make.alt' <<'END_OF_FILE'
  39. X# Makefile for inelim
  40. X
  41. X
  42. BINDIR= /usr/local/bin
  43. X
  44. SYSTEM=BSD
  45. CFLAGS  = -O -D$(SYSTEM)
  46. X
  47. COMMAND= inelim
  48. SRCS=   inelim.c unenv.c
  49. OBJS= inelim.o unenv.o
  50. MANPAGE= inelim.1net
  51. X
  52. X
  53. trap: btest
  54. X
  55. btest:  inelim
  56. X    ./inelim file1
  57. X    ./inelim -v file1
  58. X    ./inelim -p .so file1
  59. X    ./inelim file1 | ./inelim -p source
  60. X
  61. install: $(BINDIR)/$(COMMAND)
  62. X
  63. X$(BINDIR)/$(COMMAND): $(COMMAND)
  64. X    cp $(COMMAND) $@
  65. X    chmod 755 $@
  66. X
  67. bsd:
  68. X    $(MAKE) $(COMMAND) SYSTEM=BSD
  69. X
  70. att:
  71. X    $(MAKE) $(COMMAND) SYSTEM=SYSV
  72. X
  73. X$(COMMAND): $(OBJS)
  74. X    $(CC) $(LDFLAGS) -o $@ $(OBJS)
  75. X
  76. lint:
  77. X    $(LINT) -D$(SYSTEM) $(LFLAGS) $(SRCS)
  78. X
  79. clean:
  80. X    rm -f $(OBJS)
  81. X
  82. rogshar:
  83. X    shar -c -f inelim.shar $(MANPAGE) Makefile $(SRCS) file1 file2
  84. X
  85. gosshar:
  86. X    shar -c $(MANPAGE) Makefile $(SRCS) file1 file2 > incelim.shar
  87. END_OF_FILE
  88. if test 737 -ne `wc -c <'Make.alt'`; then
  89.     echo shar: \"'Make.alt'\" unpacked with wrong size!
  90. fi
  91. # end of 'Make.alt'
  92. fi
  93. if test -f 'Makefile' -a "${1}" != "-c" ; then 
  94.   echo shar: Will not clobber existing file \"'Makefile'\"
  95. else
  96. echo shar: Extracting \"'Makefile'\" \(794 characters\)
  97. sed "s/^X//" >'Makefile' <<'END_OF_FILE'
  98. X# Makefile for inelim
  99. X
  100. BINDIR= /usr/local/bin
  101. X
  102. X.SUFFIXES:
  103. X.SUFFIXES: .none
  104. X
  105. SYSTEM=BSD
  106. CFLAGS  = -O -D$(SYSTEM)
  107. X
  108. COMMAND= inelim
  109. SRCS=   inelim.c unenv.c
  110. MANPAGE= inelim.1net
  111. X
  112. OBJS= $(SRCS:.c=.o)
  113. X
  114. trap: btest
  115. X
  116. btest:  inelim
  117. X    ./inelim file1
  118. X    ./inelim -v file1
  119. X    ./inelim -p .so file1
  120. X    ./inelim file1 | ./inelim -p source
  121. X
  122. install: $(BINDIR)/$(COMMAND)
  123. X
  124. X$(BINDIR)/$(COMMAND): $$(@F)
  125. X    cp $(@F) $@
  126. X    chmod 755 $@
  127. X
  128. bsd:
  129. X    $(MAKE) $(COMMAND) SYSTEM=BSD
  130. X
  131. att:
  132. X    $(MAKE) $(COMMAND) SYSTEM=SYSV
  133. X
  134. X$(COMMAND): $(OBJS)
  135. X    $(CC) $(LDFLAGS) -o $@ $(OBJS)
  136. X
  137. X$(OBJS): $$*.c
  138. X    $(CC) $(CFLAGS) -c $*.c
  139. X
  140. lint:
  141. X    $(LINT) -D$(SYSTEM) $(LFLAGS) $(SRCS)
  142. X
  143. clean:
  144. X    rm -f $(OBJS)
  145. X
  146. rogshar:
  147. X    shar -c -f inelim.shar $(MANPAGE) Makefile $(SRCS) file1 file2
  148. X
  149. gosshar:
  150. X    shar -c $(MANPAGE) Makefile $(SRCS) file1 file2 > incelim.shar
  151. END_OF_FILE
  152. if test 794 -ne `wc -c <'Makefile'`; then
  153.     echo shar: \"'Makefile'\" unpacked with wrong size!
  154. fi
  155. # end of 'Makefile'
  156. fi
  157. if test -f 'file1' -a "${1}" != "-c" ; then 
  158.   echo shar: Will not clobber existing file \"'file1'\"
  159. else
  160. echo shar: Extracting \"'file1'\" \(121 characters\)
  161. sed "s/^X//" >'file1' <<'END_OF_FILE'
  162. knatte
  163. include file2
  164. X.so file2
  165. include $HOME/.cshrc
  166. tjatte
  167. include | awk 'BEGIN{FS=":"}{print $1}' /etc/passwd | fmt
  168. end
  169. END_OF_FILE
  170. if test 121 -ne `wc -c <'file1'`; then
  171.     echo shar: \"'file1'\" unpacked with wrong size!
  172. fi
  173. # end of 'file1'
  174. fi
  175. if test -f 'file2' -a "${1}" != "-c" ; then 
  176.   echo shar: Will not clobber existing file \"'file2'\"
  177. else
  178. echo shar: Extracting \"'file2'\" \(7 characters\)
  179. sed "s/^X//" >'file2' <<'END_OF_FILE'
  180. fnatte
  181. END_OF_FILE
  182. if test 7 -ne `wc -c <'file2'`; then
  183.     echo shar: \"'file2'\" unpacked with wrong size!
  184. fi
  185. # end of 'file2'
  186. fi
  187. if test -f 'inc-elim' -a "${1}" != "-c" ; then 
  188.   echo shar: Will not clobber existing file \"'inc-elim'\"
  189. else
  190. echo shar: Extracting \"'inc-elim'\" \(705 characters\)
  191. sed "s/^X//" >'inc-elim' <<'END_OF_FILE'
  192. XFrom enea!sten@uunet.uu.net Mon Feb 29 03:03:05 1988
  193. Received: from BBN.COM (bbn.com.ARPA) by pineapple.bbn.com id AA12423; Mon, 29 Feb 88 02:56:24 est
  194. Received: from uunet.uu.net by BBN.COM id aa22315; 29 Feb 88 2:55 EST
  195. Received: from enea.UUCP by uunet.UU.NET (5.54/1.14) with UUCP 
  196. X    id AA22935; Mon, 29 Feb 88 01:48:53 EST
  197. Received: by enea.se (5.57++/1.19)
  198. X    id AA12730; Mon, 29 Feb 88 00:59:08 +0100 (MET)
  199. Date: Mon, 29 Feb 88 00:59:08 +0100
  200. XFrom: Sten Folkerman <sten@enea.se>
  201. Message-Id: <8802282359.AA12730@enea.se>
  202. To: comp-sources-unix@enea.se
  203. Status: R
  204. X
  205. writting ./inelim.1net
  206. writting ./Makefile
  207. writting ./inelim.c
  208. writting ./unenv.c
  209. writting ./file1
  210. writting ./file2
  211. XFinished archive 1 of 1
  212. END_OF_FILE
  213. if test 705 -ne `wc -c <'inc-elim'`; then
  214.     echo shar: \"'inc-elim'\" unpacked with wrong size!
  215. fi
  216. # end of 'inc-elim'
  217. fi
  218. if test -f 'inelim.1net' -a "${1}" != "-c" ; then 
  219.   echo shar: Will not clobber existing file \"'inelim.1net'\"
  220. else
  221. echo shar: Extracting \"'inelim.1net'\" \(1571 characters\)
  222. sed "s/^X//" >'inelim.1net' <<'END_OF_FILE'
  223. X.de r$
  224. X.ds rV \\$3
  225. X.ds rD \\$4
  226. X..
  227. X.r$ $Header: inelim.1net,v 1.3 1988-02-23 16:00:12 sten Exp $
  228. X.TH INELIM 1net "ENEA DATA \*(rD"
  229. X.ds TD \fCinelim\fR
  230. X.SH NAME
  231. inelim \- eliminate include statements
  232. X.SH SYNOPSIS
  233. X.B inelim
  234. X[
  235. X.B \-v
  236. X] [
  237. X.BI \-p pattern
  238. X] [
  239. X.I files
  240. X]
  241. X.SH DESCRIPTION
  242. X\*(TD reads the specified files or the standard input and performs the
  243. implied textual inclusion. The include statement has as default the format:
  244. X.PP
  245. X\fCinclude \fIsomefile\fR
  246. X.PP
  247. when they appear in beginning of input lines.  Before \fIsomefile\fR is
  248. accessed, the file name will go through tilde and environment substitution,
  249. in a manner like \fCcsh(1)\fR.  If the file name does not begin with '/',
  250. the include file is opened relative to the directory location of the current
  251. file.  If the file name begins with '|', the rest of the line is fed to
  252. X\fCsh(1)\fR, and data from stdout is substituted in place of the include
  253. line. If The file name is just '-', the stdin will be read for data to
  254. substitute the inclusion line with.
  255. X.PP
  256. The command line options are:
  257. X.TP 2c
  258. X.BI \-p pattern
  259. X.I pattern
  260. will be used instead of \fCinclude\fR to detect include statements.
  261. Subsequent whitespace is skipped and the rest of the line is taken as the
  262. name of the file to include.
  263. X.TP
  264. X.B \-v
  265. verbose operation. Each line on the standard output is preceded by the input
  266. file name and line number.
  267. X.SH ENVIRONMENT
  268. All environment variables may be substituted into an inclusion file name.
  269. X.SH "SEE ALSO"
  270. X\fCsh(1)\fR and \fCcsh(1)\fR
  271. X.SH AUTHOR
  272. Sten Folkerman (sten@enea)
  273. X.SH BUGS
  274. No support for quotes.
  275. END_OF_FILE
  276. if test 1571 -ne `wc -c <'inelim.1net'`; then
  277.     echo shar: \"'inelim.1net'\" unpacked with wrong size!
  278. fi
  279. # end of 'inelim.1net'
  280. fi
  281. if test -f 'inelim.c' -a "${1}" != "-c" ; then 
  282.   echo shar: Will not clobber existing file \"'inelim.c'\"
  283. else
  284. echo shar: Extracting \"'inelim.c'\" \(6571 characters\)
  285. sed "s/^X//" >'inelim.c' <<'END_OF_FILE'
  286. X#ifndef lint
  287. static char *RCSid = "$Header: inelim.c,v 1.5 1988-02-29 00:39:38 sten Exp $";
  288. X#endif
  289. X
  290. X/*****************************************************************************\
  291. X*                                           *
  292. X*  NAME                                          *
  293. X*    inelim - eliminate include statements                      *
  294. X*                                           *
  295. X*  SYNOPSIS                                      *
  296. X*    inelim [-v] [-p pattern] [files]                          *
  297. X*                                           *
  298. X*  DESCRIPTION                                      *
  299. X*    inelim eliminate include statements by substituting the line with the    *
  300. X*    include statement with the contents of then file to be included. The     *
  301. X*    result is written to stdout. The -v option prints file namn and line     *
  302. X*    number at the beginning of each line. The -p option allows you to          *
  303. X*    specify an alternative pattern instead of the standard 'include'. If no  *
  304. X*    files are given, stdin is taken. Tilde and environment substitution is   *
  305. X*    performed on each include file name. If the expanded file name doesn't   *
  306. X*    begin with a '/', the directory in which we are reading from at the      *
  307. X*    moment is prefixed. If the first character in the file name is '|', the  *
  308. X*    rest is fed to "/bin/sh" and data from stdout replaces the include          *
  309. X*    line.                                      *
  310. X*                                           *
  311. X*  AUTHOR                                      *
  312. X*    sten@enea                                      *
  313. X*                                           *
  314. X\*****************************************************************************/
  315. X
  316. X/*
  317. X * $Log:    inelim.c,v $
  318. X * 
  319. X * Revision 1.5  1988-02-29  00:39:38  sten
  320. X * before public release
  321. X * 
  322. X * Revision 1.4  1988-02-23  14:54:58  sten
  323. X * incelim => inelim
  324. X * 
  325. X * Revision 1.3  1987-03-02  00:41:42  sten
  326. X * inclusion of command stdout.
  327. X * 
  328. X * Revision 1.2  1986-10-20  16:40:57  sten
  329. X * released to the Inner Circle
  330. X * 
  331. X * Revision 1.1  1986-10-05  23:09:39  sten
  332. X * Initial revision
  333. X */
  334. X
  335. X#include <stdio.h>
  336. X#include <ctype.h>
  337. X#include <assert.h>
  338. X
  339. X#ifdef BSD
  340. X#include <sys/param.h>
  341. X#endif
  342. X#ifdef V7
  343. X#define MAXPATHLEN 256
  344. X#endif
  345. X#ifdef SYSV
  346. X#include <limits.h>
  347. X#define MAXPATHLEN PATH_MAX
  348. X#endif
  349. X
  350. X#ifdef SYSV
  351. X#define rindex strrchr
  352. X#endif
  353. X
  354. X#define LLEN 256
  355. X
  356. extern char *strcat();
  357. extern char *strcpy();
  358. extern FILE *popen();
  359. extern int rindex();
  360. extern void exit();
  361. X
  362. X#define Strcpy (void) strcpy
  363. X#define Strcat (void) strcat
  364. X
  365. X#define INCLUDE "include"
  366. X
  367. char *progname;
  368. int verbose = 0;
  369. char *pattern = INCLUDE;
  370. X
  371. X/******************************************************************\
  372. X*                                    *
  373. X*  pipefile: read the file given as parameter and invoke pipefile  *
  374. X*    recursively on detected include files.               *
  375. X*                                    *
  376. X\******************************************************************/
  377. static void
  378. pipefile(cfd, cwd, cfn)
  379. XFILE *cfd;
  380. char *cwd, *cfn;
  381. X{
  382. X    int             lcnt = 0;
  383. X    char            iwd[MAXPATHLEN];
  384. X    char            line[LLEN];
  385. X
  386. X    while (fgets(line, LLEN - 1, cfd) != 0)
  387. X    {
  388. X    lcnt++;
  389. X    if (strncmp(line, pattern, strlen(pattern)) != 0)
  390. X    {
  391. X        if (verbose)
  392. X        fprintf(stdout, "%s/%s, line %d: ", cwd, cfn, lcnt);
  393. X        fputs(line, stdout);
  394. X    } else
  395. X    {
  396. X        FILE           *ifd;
  397. X        char           *ifn, *p;
  398. X        char            path[MAXPATHLEN];
  399. X        char            ppath[MAXPATHLEN];
  400. X
  401. X        for (p = line + strlen(pattern); isspace(*p); p++);
  402. X        if (untilde(ppath, p) != 0)
  403. X        {
  404. X        fprintf(stderr, "%s/%s, line %d: %s: %s\n",
  405. X            cwd, cfn, lcnt, progname, "Cannot untilde");
  406. X        exit(1);
  407. X        }
  408. X        if (ppath[0] == '|')
  409. X        {
  410. X        ppath[strlen(ppath) - 1] = '\0';
  411. X        for (p = ppath + 1; isspace(*p); p++);
  412. X        if ((ifd = popen(p, "r")) == (FILE *) NULL)
  413. X        {
  414. X            fprintf(stderr, "%s: Cannot popen %s\n", progname, ppath);
  415. X            exit(1);
  416. X        }
  417. X        pipefile(ifd, cwd, ppath);
  418. X        (void) pclose(ifd);
  419. X        } else
  420. X        {
  421. X        if ((unenv(path, ppath)) != 0)
  422. X        {
  423. X            fprintf(stderr, "%s/%s, line %d: %s: %s\n",
  424. X                cwd, cfn, lcnt, progname, "Cannot unenv");
  425. X            exit(1);
  426. X        }
  427. X        if (path[0] == '/')
  428. X            Strcpy(iwd, path);
  429. X        else
  430. X        {
  431. X            Strcpy(iwd, cwd);
  432. X            Strcat(iwd, "/");
  433. X            Strcat(iwd, path);
  434. X        }
  435. X        iwd[strlen(iwd) - 1] = '\0';
  436. X        if ((ifd = fopen(iwd, "r")) == (FILE *) NULL)
  437. X        {
  438. X            fprintf(stderr, "%s: Cannot open %s\n", progname, iwd);
  439. X            exit(1);
  440. X        }
  441. X        ifn = (char *) rindex(iwd, '/');
  442. X        *ifn++ = '\0';
  443. X        pipefile(ifd, iwd, ifn);
  444. X        (void) fclose(ifd);
  445. X        }
  446. X    }
  447. X    }
  448. X}
  449. X
  450. X#ifdef V7
  451. X/**********************************************\
  452. X*                            *
  453. X* mygetwd retrieves current working directory  *
  454. X*                            *
  455. X\**********************************************/
  456. static void
  457. mygetwd(to)
  458. char *to;
  459. X{
  460. X    FILE *pwdfd;
  461. X    char *i;
  462. X
  463. X    pwdfd = popen ("/bin/pwd\n");
  464. X    assert (pwdfd != NULL);
  465. X    i = fgets (to, MAXPATHLEN, pwdfd);
  466. X    assert (i != NULL);
  467. X    pclose (pwdfd);
  468. X    to[strlen (to) - 1] = '\0';
  469. X}
  470. X#endif
  471. X/*****************************************\
  472. X*                       *
  473. X*  usage: display correct usage and exit  *
  474. X*                       *
  475. X\*****************************************/
  476. static void
  477. usage()
  478. X{
  479. X    fprintf(stderr, "Usage: %s [-v] [-p pattern] [files]\n", progname);
  480. X    exit(1);
  481. X}
  482. X
  483. void
  484. main (argc, argv)
  485. int    argc;
  486. char    *argv[];
  487. X{
  488. X    char            sw;
  489. X    extern int      optind;
  490. X    extern char    *optarg;
  491. X    char            dir[MAXPATHLEN];
  492. X
  493. X    if ((progname = (char *)rindex(argv[0], '/')) == 0)
  494. X    progname = argv[0];
  495. X    while ((sw = getopt(argc, argv, "vp:")) != (char) EOF)
  496. X    switch (sw)
  497. X    {
  498. X    case 'v':
  499. X        verbose++;
  500. X        break;
  501. X    case 'p':
  502. X        pattern = optarg;
  503. X        break;
  504. X    case '?':
  505. X        usage();
  506. X        break;
  507. X    }
  508. X#ifdef BSD
  509. X    (void) getwd(dir);
  510. X#endif
  511. X#ifdef V7
  512. X    mygetwd(dir);
  513. X#endif
  514. X#ifdef SYSV
  515. X    (void) getcwd(dir, MAXPATHLEN);
  516. X#endif
  517. X    if (optind == argc)
  518. X    pipefile(stdin, dir, "");
  519. X    else
  520. X    for (; optind < argc; optind++)
  521. X    {
  522. X        FILE           *fd;
  523. X        char           *file;
  524. X        char            path[MAXPATHLEN];
  525. X        char            ppath[MAXPATHLEN];
  526. X
  527. X        if (strcmp(argv[optind], "-") == 0)
  528. X        pipefile(stdin, dir, "");
  529. X        else
  530. X        {
  531. X        if (untilde(ppath, argv[optind]) != 0)
  532. X        {
  533. X            fprintf(stderr, "%s: %s: %s\n",
  534. X                progname, "Cannot untilde", argv[optind]);
  535. X            exit(1);
  536. X        }
  537. X        if ((unenv(path, ppath)) != 0)
  538. X        {
  539. X            fprintf(stderr, "%s: %s: %s\n",
  540. X                progname, "Cannot unenv", argv[optind]);
  541. X            exit(1);
  542. X        }
  543. X        if (path[0] == '/')
  544. X            Strcpy(dir, path);
  545. X        else
  546. X        {
  547. X            if (dir[strlen(dir) - 1] != '/')
  548. X            Strcat(dir, "/");
  549. X            Strcat(dir, path);
  550. X        }
  551. X        if ((fd = fopen(dir, "r")) == (FILE *) NULL)
  552. X        {
  553. X            fprintf(stderr, "%s: Cannot open %s\n", progname, dir);
  554. X            exit(1);
  555. X        }
  556. X        file = (char *) rindex(dir, '/');
  557. X        *file++ = '\0';
  558. X        pipefile(fd, dir, file);
  559. X        (void) fclose(fd);
  560. X        }
  561. X    }
  562. X    exit(0);
  563. X    /* NOTREACHED */
  564. X}
  565. END_OF_FILE
  566. if test 6571 -ne `wc -c <'inelim.c'`; then
  567.     echo shar: \"'inelim.c'\" unpacked with wrong size!
  568. fi
  569. # end of 'inelim.c'
  570. fi
  571. if test -f 'unenv.c' -a "${1}" != "-c" ; then 
  572.   echo shar: Will not clobber existing file \"'unenv.c'\"
  573. else
  574. echo shar: Extracting \"'unenv.c'\" \(1692 characters\)
  575. sed "s/^X//" >'unenv.c' <<'END_OF_FILE'
  576. X/* LINTLIBRARY */
  577. X
  578. X#ifndef lint
  579. static char *RCSid = "$Header: unenv.c,v 1.1 1988-02-29 00:41:23 sten Exp $";
  580. X#endif
  581. X
  582. X/*
  583. X * $Log:    unenv.c,v $
  584. X * 
  585. X * Revision 1.1  1988-02-29  00:41:23  sten
  586. X * Initial revision
  587. X * 
  588. X * Revision 1.1  1986-10-20  16:51:22  sten
  589. X * Initial revisi
  590. X */
  591. X
  592. X#include <stdio.h>
  593. X#include <ctype.h>
  594. X#include <pwd.h>
  595. X#define Strcpy (void) strcpy
  596. X#define Strcat (void) strcat
  597. X
  598. X/****************************************\
  599. X*                      *
  600. X*  untilde: perform tilde substitution.     *
  601. X*                      *
  602. X\****************************************/
  603. X
  604. untilde(out, in)
  605. char *out, *in;
  606. X{
  607. X    if (in[0] != '~')
  608. X    {
  609. X    Strcpy(out, in);
  610. X    return (0);
  611. X    }
  612. X    if (isalnum(in[1]))
  613. X    {
  614. X    char            user[80];
  615. X    struct passwd  *pw, *getpwnam();
  616. X    char           *p, *pu;
  617. X
  618. X    p = in + 1;
  619. X    pu = user;
  620. X    while (isalnum(*p) || *p == '-')
  621. X        *pu++ = *p++;
  622. X    *pu = '\0';
  623. X    if ((pw = getpwnam(user)) == NULL)
  624. X        return (1);
  625. X    Strcpy(out, pw->pw_dir);
  626. X    Strcat(out, p);
  627. X    } else
  628. X    {
  629. X    char           *p;
  630. X
  631. X    if ((p = (char *) getenv("HOME")) == (char *) NULL)
  632. X        return (1);
  633. X    Strcpy(out, p);
  634. X    Strcat(out, in + 1);
  635. X    }
  636. X    return (0);
  637. X}
  638. X
  639. X/*******************************************\
  640. X*                         *
  641. X*  unenv: perform environment substitution  *
  642. X*                         *
  643. X\*******************************************/
  644. X
  645. unenv(out, in)
  646. char *out, *in;
  647. X{
  648. X    while (*in != '\0')
  649. X    {
  650. X    if (*in != '$')
  651. X        *out++ = *in++;
  652. X    else
  653. X    {
  654. X        char            envar[80];
  655. X        char           *p;
  656. X
  657. X        in++;
  658. X        for (p = envar; isalnum(*in);)
  659. X        *p++ = *in++;
  660. X        *p = '\0';
  661. X        if ((p = (char *) getenv(envar)) == (char *) NULL)
  662. X        return (1);
  663. X        Strcpy(out, p);
  664. X        out += strlen(out);
  665. X    }
  666. X    }
  667. X    *out = '\0';
  668. X    return (0);
  669. X}
  670. END_OF_FILE
  671. if test 1692 -ne `wc -c <'unenv.c'`; then
  672.     echo shar: \"'unenv.c'\" unpacked with wrong size!
  673. fi
  674. # end of 'unenv.c'
  675. fi
  676. echo shar: End of shell archive.
  677. exit 0
  678.